define(function(){
	
	var ec = require('echarts');
	require('echarts/chart/bar');
	require('echarts/chart/line');
	
	var my_bar = ec.init($('#qushitu').get(0));
	
	var option = {
		    title : {
		        text: '人事/行政/后勤职位平均薪资和供需指数趋势',
		        x:30,
		        subtext: ''
		    },
		    tooltip : {
		        trigger: 'axis',
		        formatter:tooltipFunc
		    },
		    legend: {
		    	x:'right',	    	
		        data:['供需指数','平均薪资']
		    },
		    dataZoom : {
                show : true,
                realtime: true,
                height:25,
                start : 0,
                end : 100,
                zoomLock:true
            },
		    toolbox: {
		        show : true,
		        orient:'vertical',	  
		        y:'bottom',
		        feature : {
		            mark : {show: true},
		            dataView : {show: true, readOnly: false},
		            magicType : {show: true, type: ['line', 'bar']},
		            restore : {show: true},
		            saveAsImage : {show: true}
		        }
		    },
		    calculable : true,
		    xAxis : [
		        {
		            type : 'category',			          
		            data : ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
		            axisLabel:{formatter:function(value){
		                return value.slice(0,4)+"年"+parseInt(value.slice(5,7))+"月";
		             	
		             }}
		        }
		    ],
		    yAxis : [		    
                {
                	'type':'value',                                     
                },
                {
                    'type':'value',
                                     
                     
                }
		    ],
		    series : [							
				{
				    name:'供需指数',
				    type:'bar',	
				    yAxisIndex:1,
				    barWidth:30,
				    data:[0.01, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
				    
				},
				{
				    name:'平均薪资',
				    type:'line',
				    yAxisIndex:0,
				    smooth: true,
				    symbol:'none',				    
				    data:[3000, 5700, 60000, 4000, 3679, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3]
				    
				}
				
		        
		    ]
		};
		                     
	/**
	 * 加载图形数据
	 */
	 function show(){
		    
		    var city_option = $('#city').val();
	    	var cate_option = $('#cate').val();
	        if(city_option==""||cate_option==""){
	        	alert("选项不能为空");
	        	return;
	        } 	      
	        my_bar.showLoading({ text: '正在努力的读取数据中...' });
	        $.ajax({
	            url: '/dashboard/zhishu/zhaopin/ajax/getQushiData',
	            type: 'post',
	            async: true,
	            data:{"city":city_option,"cate":cate_option},
	            dataType: 'json',
	            success: function(data, textStatus) {
	            	//console.log(data);
	            	var time_local = [];
	            	var gqzs = [];
	            	var avg_salary = [];
	            	var i = 0;
	            	$.each(data.dataList,function(index,value){
	            		//console.log(index+" "+this.avg_salary);
	            		time_local[i] = this.stat_date;
	            		gqzs[i] = this.gqzs;
	            		avg_salary[i] = parseFloat(this.avg_salary).toFixed(2);
	            		i++;
	            	});
	            	//console.log(gqzs);
	            	option.title.text = cate_option+'职位平均薪资和供需指数趋势';
	            	option.xAxis[0].data = time_local;
	            	option.series[0].data = gqzs;
	            	option.series[1].data = avg_salary;
	            	
	            	//小于12个点全显
	            	if(time_local.length<12){
	            		option.dataZoom.start=0;
	            		option.dataZoom.end=100;
	            	}else{
	            		option.dataZoom.start=(1-12/time_local.length)*100;
	            		option.dataZoom.end=100;
	            	}
	            	
	            	my_bar.setOption(option,true);
	            	my_bar.hideLoading();
	               
	            },
	            error : function() {
	            	my_bar.hideLoading();
	                
	            }
	        });
	    }	
    
	 //提示框
	 function  tooltipFunc(params, ticket, callback){
		 
		 var result = '<table>';
		  result += '<tr><td>'+params[0].name.slice(0,4)+'年'+parseInt(params[0].name.slice(5,7))+'月'+'</td></tr>';
		  result += '<tr><td>'+params[1].seriesName+':</td><td>'+parseFloat(params[1].value).toFixed(2)+'</td></tr>';
		  result += '<tr><td>'+params[0].seriesName+':</td><td>'+params[0].value+'</td></tr>';
		  result += '</table>';
		  return result;
	 }
	 
    
    //添加刷新事件
    $('#flushBtn').click(function(){
    	show();
    });
    	  
    
    
    var EC = {
    	show:show
    };
	
    return EC;
});